<?php

class daoUser{
	
	public static  function getUsers(){
		$provider = new Provider();
		$provider->openConnect();
		
		$strSql = "Select * from user";
		$resource = $provider->querySQL($strSql);
		
		$users;
		$i=0;
		if($resource){
			
			while($provider->read()){
				$userTemp = new dtoUser();
				$userTemp->setIntUserID($provider->getValue('UserID'));
				$userTemp->setStrUserName($provider->getValue('UserName'));
				$userTemp->setStrPass($provider->getValue('Password'));
				$userTemp->setStrFullName($provider->getValue('FullName'));
				$userTemp->setStrEmail($provider->getValue('Email'));
				$userTemp->setBlSex($provider->getValue('Sex'));
				$userTemp->setStrCountry($provider->getValue('Country'));
				$userTemp->setBlRole($provider->getValue('Role'));
				
				$users[$i] = $userTemp;
				$i++;
			}
		}
		$provider->closeConnect();
		return  $users;
	}
	
	public  static   function getUser($strUserNamePara,$strPassPara){
		$provider = new Provider();
		$provider->openConnect();
		
		//$strSql = "Select * from user where UserID=1";
		$strSql = "Select * from user where UserName='" . $strUserNamePara . "' and Password='" . $strPassPara . "'";
		$resource = $provider->querySQL($strSql);
		
		$user = new dtoUser();
		
		if($resource){
			if($provider->read()){
				
				$user->setIntUserID($provider->getValue('UserID'));
				$user->setStrUserName($provider->getValue('UserName'));
				$user->setStrPass($provider->getValue('Pass'));
				$user->setStrFullName($provider->getValue('FullName'));
				$user->setStrEmail($provider->getValue('Email'));
				$user->setBlSex($provider->getValue('Country'));
				$user->setStrCountry($provider->getValue('Country'));
				$user->setBlRole($provider->getValue('Role'));
				
				
			}
		}
		$provider->closeConnect();
		return  $user;
	}
	
	public  static   function isExist($strUserNamePara,$strPassPara){
		
		$provider = new Provider();
		$provider->openConnect();
		//$strSql = "SELECT * FROM user WHERE UserName = 'XuanTham' AND PASSWORD = '123'";

		$strSql = "Select * from user where UserName='" . $strUserNamePara . "' and Password='" . $strPassPara . "'";
		$resource = $provider->querySQL($strSql);
	
		$kq=false;
		if($resource)
				if($provider->read()) $kq=true;
				
		$provider->closeConnect();
		
		return $kq;
	
	}
	
	
}
?>